package chamber.one.thread;

import com.google.common.base.Function;
import com.google.inject.Inject;

/**
 * Created by Gerardo on 12/8/13.
 */
public class ToDividedByThreeSumFunction implements Function<Integer, Integer> {
    private final HasThreePredicate hasThree;

    @Inject
    public ToDividedByThreeSumFunction(final HasThreePredicate hasThree) {
        this.hasThree = hasThree;
    }

    @Override
    public Integer apply(Integer input) {
        int count = 0;
        for (int i = input; i >= 3; --i) {
            if (hasThree.apply(i)) {
                ++count;
            }
        }
        return count;
    }
}
